package UILayer;
import java.util.Scanner;

import ModelLayer.CurrentAccount;
import ModelLayer.MachineCollection;
import ModelLayer.Stock;



/**
 * Write a description of class MainMenuUI here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MainMenuUIOld
{
    private CustomerUI customer_ui;
    private StaffUI staff_ui;
    private OrderUI order_ui;
    private LeaseUI lease_ui;
    private StockUI stock_ui;

    /**
     * Constructor for objects of class MainMenuUI
     */
    public MainMenuUIOld()
    {
        

    }
    
    public void start_menu()
    {
        if(!(CurrentAccount.give_rank().equals("employee")))
        {
           display_current_situtation();
        }
        
        boolean exit = false;
        while (!(exit))
        {
           int choice = write_menu();
            switch(choice)
            {
                case 1 :    manage_customers();
                            break;
                case 2 :    manage_stock();
                            break;
                case 3 :    manage_orders();
                            break;
                case 4 :    manage_lease();
                            break;
                case 5 :    manage_employees();
                            break;
                default:    exit = true;
                            break;
            }
        }
    }
    
    private int write_menu()
    {
        boolean ok = false;
        int choice = 0;
        Scanner keyboard = new Scanner(System.in);       
        System.out.println("\f***MAIN MENU***");
        System.out.println("Press (1) to manage customers.");
        System.out.println("Press (2) to manage stock.");
        System.out.println("Press (3) to manage orders.");
        System.out.println("Press (4) to manage lease.");
        if(CurrentAccount.give_rank().equals("employee"))
        {
            System.out.println("Press (5) to manage your account");
        }
        else
        {
            System.out.println("Press (5) to manage accounts.");
        }
        System.out.println("Press any other number to log out.");
        while (!(ok))
        {
            try
            {
                choice = keyboard.nextInt();
                ok = true;
            }
            catch (Exception e)
            {
                System.out.println("You must provide a valid input.\nYou have to type a number");
                keyboard.nextLine();
                choice = keyboard.nextInt();
            }
        }
        keyboard.close();
        return choice;
    }
    
    private void display_current_situtation()
    {
        System.out.print("\f");
         if(MachineCollection.are_there_any_unfinished())
         {
            System.out.println("There are some new machines in the system that require finishing.");
         }
         else
         {
            System.out.println("There are no new machines in the system that require finishing.");
         }
             
         if(Stock.are_there_any_unfinished())
         {
            System.out.println("There are some new products in the system that require finishing.");
         }
         else
         {
            System.out.println("There are no new products in the system that require finishing.");
         }
         
         if (Stock.do_any_require_restocking())
         {
             System.out.println("Some products in the stock require restocking.");
         }
         else
         {
             System.out.println("No products require restocking.");
         }
         wait_for_input();
    }

    /********************************************************MENU FUNCTIONS*****************************************************/
    
    private void manage_customers()
    {
        customer_ui = new CustomerUI();
        customer_ui.start_customer_menu();
    }
    
    private void manage_stock()
    {
        stock_ui = new StockUI();
        stock_ui.stock_menu();
    }
    
    private void manage_orders()
    {
        order_ui = new OrderUI();
        order_ui.start_order_menu();
    }
    
    private void manage_lease()
    {
        lease_ui = new LeaseUI();
        lease_ui.start_lease_menu();
    }
    
    private void manage_employees()
    {
        staff_ui = new StaffUI();
        staff_ui.start_staff_menu();
        
    }
    
    /********************************************************OTHER FUNCTIONS*****************************************************/
    
    private void wait_for_input()
    {
        System.out.println("\nPRESS ENTER TO CONTINUE\n");
        Scanner keyboard = new Scanner(System.in);
        keyboard.nextLine();
        keyboard.close();
    }


}
